#include <iostream>
#include <string>
#include <string.h>
#include <pthread.h>
using namespace std;

// %p是打印地址（指针地址）的，是十六进制的形式，但是会全部打完，即有多少位打印多少位。
string toHex(pthread_t tid)
{
    char buf[64];
    snprintf(buf, sizeof(buf), "%p", tid);
    return string(buf);
}

void *ThreadFun(void *arg)
{
    const char *name = (const char *)arg;
    pthread_t id = pthread_self();
    // cout << name << ":" << id << endl;
    string id_Hex = toHex(id);
    string pinfo = string(name) + ":" + id_Hex;
    cout << pinfo << endl;
    return nullptr;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, ThreadFun, (void *)"Thread 1");
    cout << "I create a Therad is " << toHex(tid) << endl;
    pthread_join(tid, nullptr);
    return 0;
}